package com.situ.hospital.service.impl;

import com.situ.hospital.dao.IUserDAO;
import com.situ.hospital.dao.Impl.UserDAOImpl;
import com.situ.hospital.pojo.User;
import com.situ.hospital.pojo.query.UserQuery;
import com.situ.hospital.pojo.vo.UserVO;
import com.situ.hospital.service.IUserService;
import com.situ.hospital.util.PageResult;

import java.util.List;

public class UserServiceImpl implements IUserService {

    private IUserDAO userDAO = new UserDAOImpl();

    @Override
    public PageResult<UserVO> selectByPage(UserQuery userQuery) {
        List<UserVO> list = userDAO.selectByPage(userQuery);
        int totalCount = userDAO.selectTotalCount(userQuery);
        return new PageResult<>(0, "", totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        userDAO.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            userDAO.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(User user) {
        userDAO.add(user);
    }

    @Override
    public User selectById(int id) {
        return userDAO.selectById(id);
    }

    @Override
    public void update(User user) {
        userDAO.update(user);
    }

    @Override
    public void updateStatus(int id, int status) {
        userDAO.updateStatus(id, status);
    }

    @Override
    public User login(String name, String password) {
        return userDAO.login(name, password);
    }

    @Override
    public List<User> selectUser() {
        return userDAO.selectUser();
    }
}
